package com.example.sqlitedemo.dao.util;

import com.example.sqlitedemo.MyApplication;
import com.example.sqlitedemo.dao.DaoManager;
import com.example.sqlitedemo.dao.entity.FaceFeature;
import com.example.sqlitedemo.dao.entity.ShootPhoto;
import com.example.sqlitedemo.greendao.FaceFeatureDao;
import com.example.sqlitedemo.greendao.ShootPhotoDao;
import com.example.sqlitedemo.util.DebugLog;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

/**
 * Created Date 2019/2/16.
 *
 * @author liangkun
 * ClassDescription：人脸数据库工具类
 */
public class FaceDaoUtil {
    /**
     * 获取dao
     *
     * @return
     */
    public static FaceFeatureDao getFaceDao() {
        return DaoManager.getInstance(MyApplication.getContext()).getDaoSession().getFaceFeatureDao();
    }

    /**
     * 通过人脸查询有多少个md5
     *
     * @param fiuger
     */
    public static void getMd5Pic(String fiuger) {

        QueryBuilder<FaceFeature> builder = FaceDaoUtil.getFaceDao().queryBuilder();
        List<FaceFeature> picBeans = builder.where(FaceFeatureDao.Properties.FaceTonken.eq(fiuger)).list();
        for (int j = 0; j < picBeans.size(); j++) {
            String faceMd5 = picBeans.get(j).getFaceMd5();
            QueryBuilder<ShootPhoto> queryBuilder = PhotoDaoUtil.getPhotoDao().queryBuilder();
            ShootPhoto shootPhoto = queryBuilder.where(ShootPhotoDao.Properties.PhotoMd5.eq(faceMd5)).unique();
            DebugLog.d(DebugLog.LOG + "照片MD5  " + faceMd5 + " 照片名称 " + shootPhoto.getPhotoName());
//
//            List<ShootPhoto> list = queryBuilder.where(ShootPhotoDao.Properties.PhotoMd5.eq(faceMd5)).list();
//            for (int i = 0; i < list.size(); i++) {
//                ShootPhoto shootPhoto = list.get(i);
//                DebugLog.d(DebugLog.LOG + "照片MD5  " + faceMd5 + " 照片名称 " + shootPhoto.getPhotoName());
//            }

        }
    }
}
